/**
 *
 */
package com.box.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//todo 第一阶段是纯Servlet,使用注解了，并且web.xml也不需要写servlet映射了

//@WebServlet("/login")
//public class Servlet1 extends HttpServlet {
//
//	@Override
//	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//
//		System.out.println("进入了servlet这个类");
//
//		req.setAttribute("msg", "欢迎大佬！！！");
//
//		req.getRequestDispatcher("first.jsp").forward(req, resp);
//
//	}
//
//	@Override
//	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		// TODO Auto-generated method stub
//		this.doPost(req, resp);
//	}
//

//todo 第二阶段，从Servlet升级为SpringMVC的时候，最开始还是用的接口

//	public class Servlet1 implements org.springframework.web.servlet.mvc.Controller{
//
//		/**
//		 * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
//		 * @param arg0
//		 * @param arg1
//		 * @return
//		 * @throws Exception
//		 */
//		@Override
//		public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
//			ModelAndView modelAndView = new ModelAndView();
//
////		req.setAttribute("user", "个人用户信息！");这是javaweb在servlet中的写法，下面是springmvc的写法
//			modelAndView.addObject("user", "个人用户信息！");
//
////		req.getRequestDispatcher("first.jsp").forward(req, resp);
//			modelAndView.setViewName("first.jsp");
//			return modelAndView;
//		}
//
//
//
//	}

//todo 第三阶段，才变成纯注解

@Controller
public class Servlet1 {
    @RequestMapping("/login")
    public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) {
        ModelAndView modelAndView = new ModelAndView();

//		req.setAttribute("user", "个人用户信息！");这是javaweb在servlet中的写法，下面是springmvc的写法
        modelAndView.addObject("user", "个人用户信息！");

//		req.getRequestDispatcher("first.jsp").forward(req, resp);
        modelAndView.setViewName("first.jsp");
        return modelAndView;
    }
}